package com.parknfly.mycalendar;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.parknfly.mycalendar.calendar.MyDateView;

public class SelectDateDialog extends Dialog {

    MyDateView myDateView;

    TextView btnCancel, btnOk;

    public SelectDateDialog(@NonNull Context context) {
        super(context);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.date_dialog);

        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.CENTER;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            window.setAttributes(params);
        }

        // 按空白处取消对话框
        setCanceledOnTouchOutside(true);
        initUI();
    }

    private void initUI() {
        myDateView = findViewById(R.id.myDateView);
        btnCancel = findViewById(R.id.btnCancel);
        btnOk = findViewById(R.id.btnOk);

        btnOk.setOnClickListener(view -> dismiss());
        btnCancel.setOnClickListener(view -> dismiss());
    }

}
